<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display: flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px">工程名称</span>
                  <el-input v-model="tableParam.engineeringName" style="width: 180px" clearable placeholder="请输入" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">浇筑部位</span>
                  <el-input v-model="tableParam.structuralParts" style="width: 180px" clearable placeholder="请输入" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">计划时间</span>
                  <el-date-picker v-model="value1" style="width: 360px" size="medium" type="datetimerange" unlink-panels start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <div class="card_nav">
              <div>
                <el-button size="small" class="bottom_three" @click="open()">批量回弹</el-button>
              </div>
              <div>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
                <el-table-column align="center" type="selection"></el-table-column>
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :width="item.width">
                    <template slot-scope="scope">
                      <!-- <span v-if="item.label == '构件'">
                        <span class="table_link" @click="open1(scope.row)"
                          >禁用&编辑</span
                        >
                      </span> -->
                      <span v-if="item.label == '回弹状态'">
                        <span style="color: #808080">{{
                          scope.row.springbackStatus == 1
                          ? "未回弹"
                          : scope.row.springbackStatus == 2
                          ? "待回弹"
                          : "已回弹"
                          }}</span>
                      </span>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
            <div class="card_bottom">
              <div class="card_bottom_left">
                <div class="top_page_totle">总共{{ total }}条</div>
                <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
              </div>
              <div>
                <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
              </div>
            </div>
          </div>
        </div>
      </el-main>
    </el-container>
    <!-- 编辑构件 -->
    <!-- <el-dialog v-dialogDrag
      :visible.sync="addDialog"
      width="680px"
      :close-on-click-modal="false"
    >
      <span slot="title" class="dialog-title">编辑构件</span>
      <div>
        <div style="padding-bottom: 10px">
          <el-button
            size="mini"
            class="bottom_all"
            style="margin-left: 0"
            @click="add1('添加')"
          >
            <i
              class="icon iconfont iconicon_button_add"
              style="font-size: 12px"
            ></i>
            添加
          </el-button>
        </div>
        <el-table
          :header-cell-style="{ background: '#f3f6f9' }"
          :cell-style="{ borderRight: 'none' }"
          border
          stripe
          style="width: 100%"
          :data="arr1"
          tooltip-effect="dark"
        >
          <el-table-column label="构件名称" align="center">
            <template slot-scope="scope">
              <el-input
                style="width: 100%"
                v-model="scope.row.name"
                placeholder="请输入"
                clearable
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120px" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                class="bottom_two"
                @click="delete1(scope.$index)"
              >
                <i
                  class="icon iconfont iconicon_button_delete"
                  style="font-size: 12px"
                ></i>
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="addDialog = false"
          >取 消</el-button
        >
        <el-button
          class="bottom_all"
          style="margin-left: 24px"
          @click="submit2()"
          >确 定</el-button
        >
      </span>
    </el-dialog> -->
    <!-- 批量回弹 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog1" width="480px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">回弹</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate1" :rules="rules1" :inline="true" :model="fromDate1" label-width="110px">
          <el-form-item prop="recoilTime">
            <span slot="label" style="color: #ff0000">回弹时间</span>
            <el-date-picker v-model="fromDate1.recoilTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
          <el-form-item v-if="UserInfo.adminStatus == 1" prop="companyId">
            <span slot="label" style="color: #ff0000">公司</span>
            <el-select ref="selection1" v-model="fromDate1.companyId" placeholder="请选择" @change="setstationIdlist(fromDate1.companyId),$nextTick(()=>{fromDate1.company = $refs.selection1.selectedLabel})">
              <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item prop="stationId">
            <span slot="label" style="color: #ff0000">站点名称</span>
            <el-select ref="selection2" v-model="fromDate1.stationId" placeholder="请选择" @change="$nextTick(()=>{fromDate1.station = $refs.selection2.selectedLabel})">
              <el-option v-for="item in stationIdlist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item> -->
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog1 = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit1()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import { queryPage, saveManyMession } from "@/api/smart/soiltest/a_a.js";
import { getUserInfo } from "@/utils/auth.js";
import { getcompany, getUserAutList, get_simple_organization } from "@/api/common.js";
export default {
  mixins: [mixin],
  data() {
    return {
      UserInfo: "",
      companylist: [],
      stationIdlist: [],
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      /*表格数据*/
      table: [
        {
          label: "工程名称",
          width: "auto",
          prop: "engineeringName",
          status: true,
        },
        { label: "工程地址", width: "120", prop: "place", status: true },
        {
          label: "浇筑部位",
          width: "auto",
          prop: "structuralParts",
          status: true,
        },
        // { label: "构件", width: "120", prop: "", status: true },
        { label: "产品名", width: "auto", prop: "productName", status: true },
        { label: "浇筑时间", width: "120", prop: "pouringTime", status: true },
        { label: "回弹状态", width: "120", prop: "", status: true },
      ],
      pagesType: 0,
      value1: "",
      fromDate: {
        code: "",
      },
      /*回弹*/
      rules1: {
        recoilTime: [
          { required: true, message: "请选择时间", trigger: "blur" },
        ],
      },
      fromDate1: {
        recoilTime: "",
      },
      Dialog1: false,
      /*构件*/
      // arr1: [],
    };
  },
  async created() {
    this.UserInfo = await getUserInfo();
    if (this.UserInfo.adminStatus == 1) {
      /**通过typeId为公司类型id查询所有公司 */
      getcompany({ typeId: "19da56b9e85648059e3cf1e7da497da4" }).then((res) => {
        this.companylist = res.data;
      });
    } else {
      this.stationIdlist = await getUserAutList(true)
    }
    // this.setstationIdlist()
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = {
      ...this.tableParam,
      engineeringName: "",
      structuralParts: "",
    };
    this.gettableData();
  },
  watch: {
    value1() {
      this.tableParam.startTime = this.value1[0];
      this.tableParam.endTime = this.value1[1];
    },
  },
  methods: {
    /**通过站点查询公司 */
    get_simple_organizationFun(id) {
      get_simple_organization({ id: id }).then((res) => {
        this.fromDate.companyId = res.data.id
        this.fromDate.company = res.data.name
      });//查询站点所属公司
    },
    /*根据公司获取站点*/
    // setstationIdlist() {
    //   get_station_list({ parentId: this.fromDate.companyId }).then((res) => {
    //     this.stationIdlist = res.data;
    //   });
    // },
    init() {
      /*重置数据*/
      this.tableParam.engineeringName = "";
      this.tableParam.structuralParts = "";
      this.gettableData();
    },
    /*回弹*/
    open() {
      if (this.ids.length == 0) {
        this.$message({
          message: "请选择要操作的数据项",
          type: "warning",
        });
        return;
      }
      this.fromDate1.recoilTime = "";
      this.Dialog1 = true;
      setTimeout(() => {
        this.$refs.reffromDate1.clearValidate();
      }, 100);
    },
    /**回弹确认*/
    submit1() {
      let _this = this;
      _this.$refs.reffromDate1.validate((valid) => {
        if (valid) {
          this.fromDate1.listId = this.ids
          saveManyMession(this.fromDate1).then(() => {
            this.Dialog1 = false;
            this.gettableData();
          });
        } else {
          return false;
        }
      });
    },
    /*构件*/
    // open1(low) {
    //   this.low - low;
    //   this.addDialog = true;
    // },
    // add1() {
    //   let item = {};
    //   this.arr1.push(item);
    // },
    // delete1(index) {
    //   this.arr1.splice(index, 1);
    // },
    // submit2() {},
  },
};
</script>

<style lang="scss" scoped>
.el-input,
.el-select {
  width: 240px;
}
/*
 <el-link class="table_link" :underline="false">查看配合比</el-link>*/
.table_link {
  margin: 0 10px;
  color: $bg_color;
  cursor: pointer;
}

.table_link:hover {
  opacity: 0.8;
}
</style>
